package com.jgjc.controller;

import com.jgjc.entity.CommonResult;
import com.jgjc.service.BridgeTrashService;
import com.jgjc.utils.ResultResUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
public class BridgeTrashController {

    @Resource
    private BridgeTrashService bridgeTrashService;

    @GetMapping(value = "/bridge/trash/getTrashBridgeList")
    public Map<String, Object> getTrashBridgeList(HttpServletRequest request) {
        int pageSize = Integer.valueOf(request.getParameter("pageSize"));
        int currentPage = Integer.valueOf(request.getParameter("currentPage"));
        List<Map<String, Object>> listMap = bridgeTrashService.getTrashBridgeList();
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("currentPage", currentPage);
        resultMap.put("data", listMap);
        resultMap.put("pageSize", pageSize);
        resultMap.put("total", listMap.size());
        return resultMap;
    }

    @PostMapping(value = "/bridge/trash/restore")
    public Map<String, Object> restore(@RequestBody Map<String,Object> requestMap) {
        int id = (int) requestMap.get("id");
       int code = bridgeTrashService.restore(id);
       Map<String,Object> resultMap = new HashMap<>();
        ResultResUtils.ResultRes(code,resultMap);
        return resultMap;
    }

}
